import 'package:flutter/material.dart';
import 'package:flutter_svg/svg.dart';
import 'package:get/get.dart';
import 'package:seedfour/app/constants.dart';
import 'package:seedfour/app/views/module_main/main_discover/view.dart';
import 'package:seedfour/app/views/module_main/main_mine/view.dart';

import '../../../theme.dart';
import '../main_home/view.dart';
import 'logic.dart';

class MainPage extends StatelessWidget {
  MainPage({Key? key}) : super(key: key);

  final logic = Get.find<MainLogic>();

  @override
  Widget build(BuildContext context) {
    List<Widget> pages = [
      HomePage(title: logic.title.value),
      MainDiscoverPage(),
      MinePage(),
    ];

    return Scaffold(
      resizeToAvoidBottomInset: false,
      bottomNavigationBar: Obx(() => Theme(
          data: ThemeData(
            brightness: Brightness.light,
            splashColor: Colors.transparent,
            highlightColor: Colors.transparent,
          ),
          child: BottomNavigationBar(
            backgroundColor: Colors.white,
            currentIndex: logic.currentIndex.value,
            selectedItemColor: AppColor.colorMain,
            onTap: (index) => logic.changePage(index),
            selectedFontSize: kFontSizeMini,
            unselectedFontSize: kFontSizeMini,
            items: [
              BottomNavigationBarItem(
                icon: SvgPicture.asset(
                  'assets/icons/ic_home_unselected.svg',
                  width: kIconSizeMini,
                ),
                activeIcon: SvgPicture.asset(
                  'assets/icons/ic_home_selected.svg',
                  width: kIconSizeMini,
                ),
                label: '首页',
              ),
              BottomNavigationBarItem(
                icon: SvgPicture.asset(
                  'assets/icons/ic_find_unselected.svg',
                  width: kIconSizeMini,
                ),
                activeIcon: SvgPicture.asset(
                  'assets/icons/ic_find_selected.svg',
                  width: kIconSizeMini,
                ),
                label: '发现',
              ),
              BottomNavigationBarItem(
                icon: SvgPicture.asset(
                  'assets/icons/ic_mine_unselected.svg',
                  width: kIconSizeMini,
                ),
                activeIcon: SvgPicture.asset(
                  'assets/icons/ic_mine_selected.svg',
                  width: kIconSizeMini,
                ),
                label: '我的',
              ),
            ],
          ))),
      body: Obx(
        () => IndexedStack(
          index: logic.currentIndex.value,
          children: pages,
        ),
      ),
    );
  }
}
